*** Clearing Stata memory

capture log close
clear all
set more off, perm
set seed 1234

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////// Figure 1: Admission Rates for Applicants in P2 with Actual and Adjusted Scores //////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


** Opening Phase 2 norm_scores dataset 
use "Work Data/Gender_Phase2_long.dta",clear

************************* Creating variables *************************

encode subject, gen (sub)
tab subject, gen (d_sub)
label var sub "Subject"

** Subject dummies
rename d_sub1 Biology
rename d_sub2 Chemistry
rename d_sub3 Geography
rename d_sub4 History
rename d_sub5 Language
rename d_sub6 Mathematics
rename d_sub7 Physics
rename d_sub8 Portuguese
* Labels
label var Biology "Biology"
label var Chemistry "Chemistry"
label var Geography "Geography"
label var History "History"
label var Math "Mathematics"
label var Physics "Physics"
label var Portuguese "Portuguese"
label var Language "Foreign Language"

** Interaction: priority X female
gen fem_priority=female*priority
label var fem_priority "Female $\times$ Priority"

** Interaction: priority X subject
foreach v of varlist Biology-Portuguese {
gen fem_`v'=`v'*female
label var fem_`v' "Female $\times$ `v'"
gen prio_`v'=priority*`v'
label var prio_`v' "Priority $\times$ `v'"
gen fem_prio_`v'=fem_priority*`v'
label var fem_prio_`v' "Female $\times$ Priority $\times$ `v'"
}

global subject "Chemistry Geography History Mathematics Physics"
global subject_fem "fem_Chemistry fem_Geography fem_History fem_Mathematics fem_Physics"

*********************************************************************************
****************   Relative performances ****************************************
*********************************************************************************

** ENEM

foreach v in norm_enem_w {
bys year female: egen `v'_ave_g=mean(`v')
gen `v'_g=`v'-`v'_ave_g
bys year female: sum `v'_g
}
drop norm_enem_w_ave_g

* Interaction: subject X ENEM
foreach v of varlist Biology-Portuguese {
gen enem_`v'=`v'*norm_enem_w_g
label var enem_`v' "ENEM $\times$ `v'"
gen fem_enem_`v'=female*norm_enem_w_g*`v'
label var fem_enem_`v' "Female $\times$ ENEM $\times$ `v'"
forvalues i=2(1)4 {
gen enem_`v'_`i'=enem_`v'^`i'
gen fem_enem_`v'_`i'=fem_enem_`v'^`i'
}
sum enem_`v'* fem_enem_`v'*
}

global g_pol_enem_sub "enem_Chemistry* enem_Geography* enem_History* enem_Mathematics* enem_Physics*"
d $g_pol_enem_sub

* Priority x relative performance in ENEM:
foreach v in norm_enem_w {
gen `v'_priority_g=`v'_g*priority
forvalues i=2(1)4 {
gen `v'_priority_g`i'=`v'_g^`i'*priority
sum `v'_priority_g`i'
}
}

global g_norm_enem_w_prio norm_enem_w_priority_g*
d $g_norm_enem_w_prio

** Phase 1 scores

foreach v in norm_p1score {
bys year subject female: egen gs_`v'_ave=mean(`v')
gen gs_`v'=`v'-gs_`v'_ave
bys year female subject: sum gs_`v'
drop gs_`v'_ave
forvalues i=2(1)4 {
gen gs_`v'`i'=gs_`v'^`i'
sum gs_`v'`i'
}

global gs_pol_`v' gs_`v' gs_`v'2 gs_`v'3 gs_`v'4
d $gs_pol_`v'

* Priority x Phase 1 scores:
gen gs_`v'_prio=gs_`v'*priority
forvalues i=2(1)4 {
gen gs_`v'_prio`i'=gs_`v'`i'*priority
sum gs_`v'_prio*
}
}

global gs_pol_norm_p1score_prio gs_norm_p1score_prio*
d $gs_pol_norm_p1score_prio

*********************************************************************************
**************** Main sample ****************************************************
*********************************************************************************

* 1) Only years before the affirmative action took place
drop if aa_year==1
drop if year==2000
tab year

*********************************************************************************
****************   Regressions **************************************************
*********************************************************************************

*** # of priority discipline per applicant
bys inscri2: egen n_priority=sum(priority) if subject!="port" & subject!="lang"
sum n_priority
tab n_priority

 *************************
 ****** Raw Scores  ******
 *************************

estimates clear

reghdfe score priority fem_priority $subject $subject_fem $g_pol_enem_sub $g_norm_enem_w_prio $gs_pol_norm_p1score $gs_pol_norm_p1score_prio if subject!="port" & subject!="lang", cluster(inscri2) absorb(inscri2)
gen b_fem_prio=_b[fem_priority]
gen adj_score=score
* Priority subjects: 
replace adj_score=score - _b[fem_priority] if subject!="port" & subject!="lang" &  female==1   & priority==1
* Non priority subjects:
sum score adj_score if n_priority==0 
replace adj_score=score + (n_priority/(6-n_priority))*(_b[fem_priority]) if subject!="port" & subject!="lang" &  female==1   & priority==0

*** Calculating Adjusted Scores 
keep inscri2 subject year adj_score
rename adj_score adj
reshape wide adj, i(inscri2) j(subject) string
save "Work Data/Adjusted_Scores.dta", replace

** Opening Phase 2 norm_scores dataset 
use "Work Data/Gender_Phase2_long.dta",clear
drop if aa_year==1
drop if year==2000
merge m:1 inscri2 year using "Work Data/Adjusted_Scores.dta"

* Keep only the variables we need:
keep inscri2 year sex career_choice pass_st1 enroll career_enroll aa_year aa_2005 all_public vis_min minority_all_public vis_min_aa all_public_aa minority_all_public_aa ///
female curso curso2 curso3 aprova curpas convoc yearconcl option *_st1 *_st2 essay_corr enem2 enem NP1_noENEM NP NENEM NP_st1 req_apt apt_NP pri_NP_st2 ///
nonpri_NP_st2 NPO wNPO wNPO_aa NPOwo wNPOwo missing_p1* missing_p2* adj*
drop average* num_pri_NP_st2 num_nonpri_NP_st2 pri_NP_st2 nonpri_NP_st2 *_NP_st2

duplicates drop

codebook inscri2

foreach i in port biol chem hist phy geog math lang {	
gen `i'_tot_st2=`i'1_st2+`i'2_st2+`i'3_st2+`i'4_st2+`i'5_st2+`i'6_st2+`i'7_st2+`i'8_st2+`i'9_st2+`i'10_st2+`i'11_st2+`i'12_st2
sum `i'_tot_st2
}

*********************************************************************************
**************** Phase 2 ********************************************************
*********************************************************************************

gen ELIM_2 = 0
foreach x in port biol chem hist phy geog math lang{
replace ELIM_2 = 1 if `x'_attn_st2 == 2
}
foreach x in port biol chem hist phy geog math lang{
replace ELIM_2 = 1 if `x'_tot_st2 == 0
}

gen ELIM_apt=0
replace ELIM_apt = 1 if (aptd_attn_st2 == 2 &  req_apt==1)
replace ELIM_apt = 1 if (aptd_st2<30 & year<2007 & req_apt==1)

/*	We then need to generate the standardized score. We start with the regular disciplines.*/

foreach z in "" adj  {
foreach x in port biol chem hist phy geog math lang {
gen `z'`x'_NP_st2_p = .
gen `z'`x'_NP_st2 = .
}
}

* For regular grades: 
forvalues y=0(1)4 {
foreach x in port biol chem hist phy geog math lang {
sum `x'_tot_st2 if (year == 200`y' & `x'_attn_st2 == 1)
scalar M_`x'_`y' = r(mean)
scalar D_`x'_`y' = r(sd)
replace `x'_NP_st2 = (((`x'_tot_st2 - M_`x'_`y')*100)/D_`x'_`y')+500 if year == 200`y'
}
}

* For adjusted regular grades:
forvalues y=0(1)4 {
foreach z in adj  {
foreach x in port biol chem hist phy geog math lang{
sum `z'`x' if (year == 200`y' & `x'_attn_st2 == 1)
scalar M_`z'`x'_`y' = r(mean)
scalar D_`z'`x'_`y' = r(sd)
replace `z'`x'_NP_st2 = (((`z'`x' - M_`z'`x'_`y')*100)/D_`z'`x'_`y')+500 if year == 200`y'
}
}
}

*****************************************************************************
*																			*
* FINAL SCORE: THREE CHOICES												*
*																			*
*****************************************************************************

* For regular grades:

/*	Calculate wNPO_1, wNPO_2 and wNPO_3 */

foreach x in 1 2 3 {

/* Replace 31 by 62 */
replace career`x'=62 if career`x'==31

/*	Identification of priority discipline */
merge m:1 career`x' using "Original data/priority_discipline.dta"
drop if _merge==2
drop _merge

/*	Adjust for changes in the priority disciplines for certain careers */
replace prior_hist=0 if (year==2000 | year==2001 | year==2002) & career`x'==45
replace prior_math=1 if (year==2000 | year==2001) & career`x'==30
replace prior_hist=0 if (year==2000 | year==2001 | year==2002) & career`x'==27
replace prior_hist=0 if year==2000 & career`x'==25
replace prior_chem=1 if (year==2000 | year==2001) & career`x'==14

/*	Generate a variable indicating if the major choice needs aptitude test. Note that this has to be changed for each different choice. */
gen req_apt_temp = (career`x' == 14 | career`x' == 23 | career`x' == 25 | career`x' ==26 | career`x' == 48 | career`x' == 90 | ///
career`x' == 91 | career`x' == 92 | career`x' == 87 | career`x' == 93| career`x' == 100 )

/*	First, calculate the sum of the grades of priority disciplines and then the number of priority disciplines required in that career choice.*/

foreach z in "" adj  {
	gen `z'pri_NP_st2 = `z'port_NP_st2*prior_port +`z'biol_NP_st2*prior_biol+ `z'chem_NP_st2*prior_chem ///
+`z'hist_NP_st2*prior_hist+ `z'phy_NP_st2*prior_phy + `z'geog_NP_st2*prior_geog + ///
`z'math_NP_st2*prior_math + `z'lang_NP_st2*prior_lang
}

gen num_pri_NP_st2=prior_port +prior_biol+ prior_chem + prior_hist+ ///
prior_phy + prior_geog + prior_math + prior_lang

/*	Second, calculate the sum of the grades of non-priority disciplines and then the number of non-priority disciplines required in that career choice,
	which is, by definition, 8 minus the number of priority disciplines. */

foreach z in "" adj {
gen `z'nonpri_NP_st2 = `z'port_NP_st2*(1-prior_port) +`z'biol_NP_st2*(1-prior_biol)+ `z'chem_NP_st2*(1-prior_chem) ///
+`z'hist_NP_st2*(1-prior_hist)+ `z'phy_NP_st2*(1-prior_phy) + `z'geog_NP_st2*(1-prior_geog) + ///
`z'math_NP_st2*(1-prior_math) + `z'lang_NP_st2*(1-prior_lang)
}

gen num_nonpri_NP_st2=8-num_pri_NP_st2

/*	Third, calculate the weighted aptitude test normalized score.
	The weighted aptitutde test is weighted by 2 except for dentistry. 
*/

gen wapt_NP = 2* apt_NP if req_apt_temp == 1
replace wapt_NP = apt_NP if career`x' == 14
replace wapt_NP = 0 if req_apt_temp == 0

/*	Fourth, calculate the final score NPO. */

foreach z in "" adj {
gen `z'NPO`x' = .
replace `z'NPO`x' = 2*NP_st1 + 2*`z'pri_NP_st2 +`z'nonpri_NP_st2
replace `z'NPO`x' = 2*NP_st1 + 2*`z'pri_NP_st2 +`z'nonpri_NP_st2 +wapt_NP if req_apt_temp == 1

gen `z'wNPO`x' = `z'NPO`x'/(2+2*num_pri_NP_st2+num_nonpri_NP_st2)
replace `z'wNPO`x' = `z'NPO`x'/(2+2*num_pri_NP_st2+num_nonpri_NP_st2+2) if req_apt_temp == 1
replace `z'wNPO`x' = `z'NPO`x'/(2+2*num_pri_NP_st2+num_nonpri_NP_st2+1) if career`x' == 14
}

drop *prior* *pri_NP_st2 *num_pri_NP_st2 *nonpri_NP_st2 *num_nonpri_NP_st2 *wapt_NP *req_apt_temp
}

*****************************************************************************
*  																			*
* ADMISSION: ROUND 1														*
*																			*
*****************************************************************************

/* 
	2001-2003: Until 2003, only the applicants who obtained the priority discipline cutoff grade (nota de corte prioritaria,
	(NCP)) were admitted. Eligible candidates were then ranked in decreasing order of NPO and were admitted
	until all slots were attributed to candidates choosing the major as first choice.

	2004-2008: those who opted for the major as first option and obtained, in the priority subjects, (non-standardized
	or standardized) grades that are larger or equal to the major's NMO.

	Thus, the first round is similar for all years, as it takes only into account the first choice of applicants. 
	Until 2003, the criterion was to get 30\% of the non-standardized priority discipline grade for most majors, and 20\% for few.
	Starting in 2004, they need grades in priority subjects that are larger or equal to the major's NMO
*/

/*	Insert NMO and NCP scores and make adjustments for some careers */

joinby career1 using "Original data/NMO_NCP.dta", unmatched(master)
tab _merge
drop _merge
drop NMO07 NCP07 NMO08 NCP08
rename NMO 	 NMO_1
rename NCP 	 NCP_1
replace NMO_1=27 if (year==2000 | year==2001 | year==2002 ) & career1==12
replace NCP_1=18 if (year==2000 | year==2001) & career1==56

/*	Note that we need to re-identify priority disciplines. The alternative method, which consists of keeping the records, would imply 
	that we would need to store many variables. So I prefer to reinsert the priority disciplines file and its corrections here.
*/

joinby career1 using "Original data/priority_discipline.dta", unmatched(master)
tab _merge
drop _merge
replace prior_hist=0 if (year==2000 | year==2001 | year==2002) & career1==45
replace prior_math=1 if (year==2000 | year==2001) & career1==30
replace prior_hist=0 if (year==2000 | year==2001 | year==2002) & career1==27
replace prior_hist=0 if (year==2000 | year==2001 | year==2002 | year==2003)  & career1==25
replace prior_chem=1 if (year==2000 | year==2001) & career1==14

/* 	2001-2003: Check if priority discipline cutoff grade were obtained by candidates.
	Note that for the period 2001-2003, these cutoffs are based on the non-standardized grades.
*/

gen ELIM_O1=0
foreach x in port biol chem hist phy geog math lang{
	replace ELIM_O1=1 if round(`x'_tot_st2)<NCP_1 & prior_`x'==1 & year<2004
}

foreach z in adj {
gen `z'ELIM_O1=0
foreach x in port biol chem hist phy geog math lang{
	replace `z'ELIM_O1=1 if round(`z'`x')<NCP_1 & prior_`x'==1 & year<2004
}
}

foreach z in "" adj {
bys year career1: egen `z'rank1 = rank(-`z'wNPO1) if ELIM_2==0 & `z'ELIM_O1==0 & ELIM_apt==0, track
}

*********************************************************************************
**************** Count admitted by major and year *******************************
*********************************************************************************

preserve
drop if convoc==0
tab year
keep career_enroll year convoc enroll
collapse (sum) convoc, by(career_enroll year)
rename career_enroll career1
rename convoc nconvoc
save "Work Data/Admitted_01_04.dta", replace
restore

joinby career1 year using "Work Data/Admitted_01_04.dta", unmatched(master)
tab _merge year
drop _merge

/* Generate a variable that indicates whether the candidate was admitted in round 1.*/

foreach z in "" adj {
gen `z'pass_st2=(`z'rank1<=nconvoc & nconvoc!=. & ELIM_2==0 & `z'ELIM_O1==0 & ELIM_apt==0)
}

/* 	There are four special groups that are treated differently in terms of options and admission. These will be dealt with below,
	but in the meanwhile we erase the indicator that applicants passed these careers.
*/

foreach z in "" adj  {
replace `z'pass_st2=0 if (career1==41 | career1==39 | career1==81 | career1==75)
gen `z'career_convoc=career1 if `z'pass_st2==1

}

/* 	Deal with Eletrical Engineering, Chemical Engineering, Nursing and Medicine: If an applicant chooses one of these majors 
	as first option and the other as second (say, Medicine Unicamp and Medicine Famerp), and not third option, the ranking is 
	made as if these were only one option. Applicants are admitted in these choices, depending on available slots, and other 
	applicants are admitted after, using the regular rules.
	Most students place the majors suggested as first and second option, but some do not.
*/

gen 	career1t=4141 if career1==41
replace career1t=4141 if career1==11 & career2==41
replace career1t=3939 if career1==39
replace career1t=3939 if career1==9  & career2==39
replace career1t=8181 if career1==81
replace career1t=8181 if career1==21 & career2==81
replace career1t=7575 if career1==75 
replace career1t=7575 if career1==15 & career2==75

tab career1t
tab career1 career1t
count if career1t==.

foreach z in "" adj  {
bys year career1t: egen `z'rank1t = rank(-`z'wNPO1) if ELIM_2==0 & `z'ELIM_O1==0 & ELIM_apt==0 & `z'pass_st2==0 & career1t!=., track
}


/*	Replace the maximum number of spots for the four careers that have different criteria
*/

foreach i in 41 39 75 81{
gen nconvoc_`i'_t=nconvoc if career1==`i'
bys year: egen nconvoc_`i'=mean(nconvoc_`i'_t)
drop nconvoc_`i'_t
}

foreach z in "" adj  {
foreach i in 41 39 81 75{
replace `z'pass_st2=1 if career1t==`i'`i' & (`z'rank1t<=nconvoc_`i' & nconvoc_`i'!=. & ELIM_2==0 & `z'ELIM_O1==0 & ELIM_apt==0)
replace `z'career_convoc=`i' if career1t==`i'`i' & (`z'rank1t<=nconvoc_`i' & nconvoc_`i'!=. & ELIM_2==0 & `z'ELIM_O1==0 & ELIM_apt==0)
}
}

*********************************************************************************
****************   Analysis	*****************************************************
*********************************************************************************

** By Careers, restricting to majors that have lower admission rates than the overall average

foreach x in adj  {

preserve

tab1 pass_st2 `x'pass_st2

foreach v of varlist pass_st2 `x'pass_st2  {
gen fem`v'=`v' if female==1
gen male`v'=`v' if female==0
sum `v' fem`v'
}

tab  pass_st2, sum(career_convoc) mi 
tab  `x'pass_st2, sum(career_convoc) mi 
compare career_convoc `x'career_convoc if pass_st2==1
tab career_convoc `x'career_convoc if pass_st2==1 &  career_convoc~=`x'career_convoc & `x'career_convoc~=. // special groups
** We will aggregate this careers in a single code
replace career_convoc=`x'career_convoc if career_convoc==.
replace career_convoc=career_choice if career_convoc==.
compare career_convoc career_choice if pass_st2==0

** Overall admission rates
sum pass_st2
scalar overall_pass_rate=r(mean)
sum `x'pass_st2
scalar overall_`x'pass_rate=r(mean)

*** Female admission rates
sum fempass_st2
scalar overall_female_pass_rate=r(mean)
sum fem`x'pass_st2
scalar overall_`x'female_pass_rate=r(mean)

*** Male admission rates
sum malepass_st2
scalar overall_male_pass_rate=r(mean)
sum male`x'pass_st2
scalar overall_`x'male_pass_rate=r(mean)

* Aggregate careers
gen career_ag=career_choice
replace career_ag=4141 if career_choice==11 | career_choice==41
replace career_ag=3939 if career_choice==39 | career_choice==9
replace career_ag=8181 if career_choice==21 | career_choice==81
replace career_ag=7575 if career_choice==75 | career_choice==15
tab career_ag career_choice

* By career

gen total_applicants=1
gen female_applicants=female

collapse (sum) pass_st2 `x'pass_st2 fempass_st2 malepass_st2 fem`x'pass_st2 male`x'pass_st2 female_applicants total_applicants, by(career_ag)

foreach v of varlist pass_st2 `x'pass_st2 {
gen `v'_career=`v'/total_applicants
sum `v'_career
gen fem`v'_career=fem`v'/female_applicants
sum fem`v'_career
gen male`v'_career=male`v'/(total_applicants-female_applicants)
sum male`v'_career
}

** Linking Career Name to their Code
rename career_ag career_choice
merge 1:1 career_choice using "Work Data/Dictionary career code.dta"
tab _merge
tab career_choice if _merge==1 // 4 careers that we aggregate

tab Career_name if career_choice==11 | career_choice==41
replace Career_name="Electrical Engineering" if career_choice==4141 

tab Career_name if career_choice==39 | career_choice==9
replace Career_name="Chemical Engineering" if career_choice==3939 

tab Career_name if career_choice==21 | career_choice==81
replace Career_name="Nursing" if career_choice==8181 

tab Career_name if career_choice==75 | career_choice==15
replace Career_name="Medicine" if career_choice==7575 

list if _merge
drop if _merge==2
drop _merge

gen career_low_admission = (pass_st2_career <overall_pass_rate)
sum pass_st2_career
sum pass_st2_career if career_low_admission ==1
tab Career_name if career_low_admission ==1

keep if career_low_admission ==1
tab Career_name

set obs `=_N+1'
replace Career_name="Overall" if Career_name==""
replace pass_st2_career=overall_pass_rate if Career_name=="Overall"
replace fempass_st2_career=overall_female_pass_rate if Career_name=="Overall"
replace malepass_st2_career=overall_male_pass_rate if Career_name=="Overall"
replace `x'pass_st2_career=overall_`x'pass_rate if Career_name=="Overall"
replace fem`x'pass_st2_career=overall_`x'female_pass_rate if Career_name=="Overall"
replace male`x'pass_st2_career=overall_`x'male_pass_rate if Career_name=="Overall"

tab Career_name
replace Career_name="Control & Autom. Eng." if Career_name=="Control and Automation Engineering"
replace Career_name="Social Commun." if Career_name=="Social Communication (Media Studies)"
replace Career_name="Biological Sc." if Career_name=="Biological Sciences"
replace Career_name="Biological Sc. (T)" if Career_name=="Biological Sciences (T)"
replace Career_name="Computer Eng." if Career_name=="Computer Engineering"
replace Career_name="Computer Sc." if Career_name=="Computer Science"
replace Career_name="Economics (Eve.)" if Curso=="Ciências Econômicas (Noturno)"
replace Career_name="Food Eng. (Eve.)" if Curso=="Engenharia de Alimentos (Noturno)"
replace Career_name="Mechanical Eng." if Career_name=="Mechanical Engineering"
replace Career_name="Food Eng." if Career_name=="Food Engineering"
replace Career_name="Electrical Eng." if Career_name=="Electrical Engineering"
replace Career_name="Chemical Eng." if Career_name=="Chemical Engineering"
replace Career_name="Environmental San. Tech." if Career_name=="Environmental Sanitation Technology"

encode Career_name , generate(career_str) 
egen Career = rank(pass_st2_career)
labmask Career, values( career_str ) decode

set scheme s1color

foreach v of varlist *_career {
replace `v'=100* `v'
format `v' %3.1f
}


gen clock_female=3

gen clock_male=3
replace clock_male=2 if Career==2
replace clock_male=2 if Career==4
replace clock_male=2 if Career==5
replace clock_male=2 if Career==7
replace clock_male=2 if Career==9
replace clock_male=2 if Career==10
replace clock_male=2 if Career==11
replace clock_male=2 if Career==12
replace clock_male=2 if Career==14
replace clock_male=2 if Career==15
replace clock_male=2 if Career==18

gen clock_male`x'=3
replace clock_male`x'=4 if Career==16

gen clock_female`x'=3
replace clock_female`x'=2 if Career==3
replace clock_female`x'=2 if Career==4
replace clock_female`x'=2 if Career==5
replace clock_female`x'=2 if Career==9
replace clock_female`x'=2 if Career==10
replace clock_female`x'=2 if Career==11
replace clock_female`x'=2 if Career==12

twoway scatter fempass_st2_career Career, msymbol(smcircle) mlabel(fempass_st2_career) mlabvpos(clock_female) mlabsize(4pt) /// 
|| scatter fem`x'pass_st2_career  Career , mlabel(fem`x'pass_st2_career) mlabvpos(clock_female`x') mlabsize(4pt) msymbol(smsquare_hollow)  ///
|| scatter malepass_st2_career  Career, mlabel(malepass_st2_career ) mlabvpos(clock_male) mlabsize(4pt)  msymbol(smtriangle) ///
|| scatter male`x'pass_st2_career  Career, mlabel(male`x'pass_st2_career ) mlabvpos(clock_male`x') mlabsize(4pt)  msymbol(smdiamond_hollow) ///
ylabel(15(5)35,labsize(8pt) angle(horizontal) format(%3.0f)) yscale(range(15 35)) legend(order(1 "Female" 2 "Adjusted female" 3 "Male" 4 "Adjusted male") size(8pt) row(1) ) ///
 xlab(1/18, val angle(45) labsize(8pt))  saving("Output/low_admission_rate_`x'_lower_P1", replace)  xtitle("") ytitle("")  ///
 plotregion(margin(large))  ysize(6)
 
 tab Career, sum(fempass_st2_career)
 tab Career, sum(malepass_st2_career)
 tab Career, sum(fem`x'pass_st2_career)
 tab Career, sum(male`x'pass_st2_career)

graph export "Output/low_admission_rate_`x'_lower_P1.eps", as(eps) replace 

restore
}


